package com.lzh.chatnote.chat.service.strategy;


import com.lzh.chatnote.common.exception.CommonErrorEnum;
import com.lzh.chatnote.common.utils.AssertUtil;

import java.util.HashMap;
import java.util.Map;

public class MsgFactoryHandler {

    private static  final Map<Integer, AbstractMsgHandler> msgHandlerMap = new HashMap<>();

    //注册到工厂里面
    public static void register(Integer code,AbstractMsgHandler msgHandler){
        msgHandlerMap.put(code ,msgHandler);
    }

    //获取工厂里面的实例
    public static AbstractMsgHandler getStrategyNoNull(Integer code){
        AbstractMsgHandler abstractMsgHandler = msgHandlerMap.get(code);
        AssertUtil.isNotEmpty(abstractMsgHandler, CommonErrorEnum.PARAM_VALID);
        return abstractMsgHandler;
    }



}
